package com.jiuling.apis.controller;

import com.alibaba.fastjson.JSON;
import com.jiuling.apis.interfaces.DubboServiceI;
import com.jswzc.framework.controller.BaseController;
import com.jswzc.pay.service.balanceService.BalanceServiceI;
import com.jswzc.pay.service.balanceService.BrandOrderServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by liujiajia on 2017/5/11.
 */
@Controller
@RequestMapping("/demo")
public class DemoController extends BaseController{

    @Autowired
    private DubboServiceI dubboService;
    @Autowired
    private BrandOrderServiceI brandOrderService;
    @Autowired
    private BalanceServiceI balanceService;
    @RequestMapping("/demoTest")
    public void demoTest(HttpServletResponse response){
        try {
            String ss= dubboService.saveDemo();
            writeJson(ss,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 用户新久零券接口
     */
    @RequestMapping(value="/updateUserBalance90")
    public synchronized void updateUserBalance90(@RequestParam(value="json", required=true) String json, HttpServletResponse response){
        Map<String,Object> map=new HashMap<String, Object>();
        Map<String,Object> res = new HashMap<String, Object>();
        try {
            map= JSON.parseObject(json,Map.class);
            res=balanceService.updateUserBalance90(map);//处理用户久零券

        } catch (Exception e) {
            res.put("flag", "1");
            res.put("msg","操作失败,参数错误");

        }
        writeJson(res,response);
    }

    /**
     * 用户久零贝接口
     */
    @RequestMapping(value="/operUserCoin90")
    public synchronized void operUserCoin90(@RequestParam(value="json", required=true) String json, HttpServletResponse response){
        Map<String,Object> map=new HashMap<String, Object>();
        Map<String,Object> res = new HashMap<String, Object>();
        try {
            map= JSON.parseObject(json,Map.class);
            res=balanceService.operUserCoin90(map);//处理用户久零贝

        } catch (Exception e) {
            res.put("flag", "1");
            res.put("msg","操作失败,参数错误");

        }
        writeJson(res,response);
    }



}
